<?php

use yii\helpers\Html;
use yii\widgets\ActiveForm;
use backend\models\Product;
use backend\models\Category;

/* @var $this yii\web\View */
/* @var $model backend\models\Product */
/* @var $form yii\widgets\ActiveForm */
?>

<div class="product-form">

    <?php
    $form = ActiveForm::begin([
                'id' => 'upload',
                'enableAjaxValidation' => FALSE,
                'options' => ['enctype' => 'multipart/form-data']
    ]);
    ?>

    <?= $form->field($model, 'categoryId')->dropDownList(Category::getCategoryList_S(1)) ?>

    <?= $form->field($model, 'title')->textInput(['maxlength' => true]) ?>

    <?= $form->field($model, 'description')->textarea(['rows' => 6]) ?>

    <?= $form->field($model, 'number')->textInput() ?>

    <?= $form->field($model, 'price')->textInput(['maxlength' => true]) ?>


    <?= $form->field($model, 'issale')->radioList(Product::$list) ?>

    <?= $form->field($model, 'ishot')->radioList(Product::$list) ?>

    <?= $form->field($model, 'istui')->radioList(Product::$list) ?>

    <?= $form->field($model, 'saleprice')->textInput(['maxlength' => true]) ?>

    <?= $form->field($model, 'ison')->radioList(Product::$list) ?>

    <?php
    ?>
    <?php
    echo $form->field($cover, 'file')->label("商品封面")->widget(kartik\file\FileInput::classname(), [
        'options' => ['multiple' => true],
    ]);
    if (isset($model->cover)) {
        echo "<img src= //$model->cover style='width: 100px;height: 100px;'> ";
    }
    ?>
    <?php
    echo $form->field($pictures, 'file[]')->label("商品图片")->widget(kartik\file\FileInput::classname(), [
        'options' => ['multiple' => true],
    ]);
    if (isset($model->cover)) {
        echo \backend\controllers\ProductController::translatePictures($model->productId, $model->pictures, 0);
    }
    ?>
    <div class="form-group">
        <?= Html::submitButton($model->isNewRecord ? '添加' : '更新', ['class' => $model->isNewRecord ? 'btn btn-success' : 'btn btn-primary']) ?>
    </div>

    <?php
    ActiveForm::end();
    ?>

</div>
<script type="text/javascript">

    function doDelete(id, key) {
        var r = confirm("你确定要删除吗?");
        if (r == true) {
//            alert("66");
            $.ajax({
                type: "POST",
                url: '<?php echo Yii::$app->request->baseUrl . '/product/remove'; ?>',
                data: {id: id, key: key},
//                processData: false,
//                contentType: false,
//                 dataType:"json",
                success: function (data) {
//                    alert("删除成功");
                    console.log(data);
                    var div = document.getElementById("" + data);
                    div.style.display = 'none';
                },
                error: function (data) {
                    alert("删除失败");
                    console.log(data);
                },
//                beforeSend: loading,
//                complete: complete
            })
        }
    }


</script>

